﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Common;
using CNCSoft.EData;

namespace CNCSoft.ErpApps.TMS.Test
{
    public partial class frmMK : Form
    {
        private SqlConnection conn = new SqlConnection(GlobalVariable.WSInfo.ConnectionString);
        private DataSet ds;
        private string _madethi;
        private int _thoigianlambai, _listen, _read;

        public frmMK(string madethi, string thoigianlambai)
        {
            InitializeComponent();
            this._madethi = madethi;
            this._thoigianlambai = Convert.ToInt32(thoigianlambai);
        }

        private void frmMK_Load(object sender, EventArgs e)
        {
            ds = new DataSet();

            slook_Enquiry.Enabled = true;
            LoadEnquiry();
            slook_Enquiry.Properties.DataSource = ds.Tables["TableEnquiry"];
            slook_Enquiry.Properties.DisplayMember = "FullName";
            slook_Enquiry.Properties.ValueMember = "EnquiryNumber";

            pnl_Main.VerticalScroll.Enabled = true;
            AddFile(String.Format("{0}.rtf", _madethi));

            txtTestDate.Enabled = false;
            btn_Start.Enabled = true;
            btn_Finish.Enabled = false;
            timerTest.Stop();
            txtTestDate.EditValue = DateTime.Now.ToShortDateString();

            //I/ Listening
            Label lbI = AddLabel(this.pnl_Main, "lbI", "I/ Listening.", Color.Red, pnl_Listening.Bottom);

            //I.1
            AddListening1(1, 6, lbI.Location.Y);
        }

        #region "Load de thi"
        private void AddFile(string filename)
        {
            try
            {
                pnl_Listening.Visible = true;
                pnl_Listening.Width = 1024;
                pnl_Listening.Height = 800;
                rich_Listening.LoadFile(Environment.CurrentDirectory + "/" + filename);   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddListening1(int begin, int end, int y)
        {
            try
            {
                y += 20;
                Label lbI1 = AddLabel(this.pnl_Main, "lbI1", "I. Listen and match. (MK1-MK3)", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupI1 = new Panel();
                    groupI1.Location = new Point(10, y + 20);
                    groupI1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupI1.AutoSize = true;
                    groupI1.Name = "grpI1" + index;
                    this.pnl_Main.Controls.Add(groupI1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupI1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtI1" + index;
                    this.pnl_Main.Controls[groupI1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //y = AddABCD(this.pnl_Main, begin, end, y);

                //Add I.2
                AddListening2(1, 6, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddListening2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbI2 = AddLabel(this.pnl_Main, "lbI2", "II. Listen and fill in the blanks: (MK4-MK6)", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupI2 = new Panel();
                    groupI2.Location = new Point(10, y + 20);
                    groupI2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupI2.AutoSize = true;
                    groupI2.Name = "grpI2" + index;
                    this.pnl_Main.Controls.Add(groupI2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupI2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtI2" + index;
                    this.pnl_Main.Controls[groupI2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                AddListening3(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddListening3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbI3 = AddLabel(this.pnl_Main, "lbI3", "III. Listen and write: (MK7-MK8)", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupI3 = new Panel();
                    groupI3.Location = new Point(10, y + 20);
                    groupI3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupI3.AutoSize = true;
                    groupI3.Name = "grpI3" + index;
                    this.pnl_Main.Controls.Add(groupI3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupI3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 300;
                    txt1.Name = "txtI3" + index;
                    this.pnl_Main.Controls[groupI3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add II Reading
                Label lbII = AddLabel(this.pnl_Main, "lbII", "II/ Reading", Color.Red, y + 50);

                //Add MK1
                Label lbMK1 = AddLabel(this.pnl_Main, "lbMK1", "MK1", Color.Red, lbII.Location.Y + 50);

                AddII_1(1, 7, lbMK1.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //II MK1
        private void AddII_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbII1 = AddLabel(this.pnl_Main, "lbII1", "I/ Fill in the missing alphabet letters", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupII1 = new Panel();
                    groupII1.Location = new Point(10, y + 20);
                    groupII1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupII1.AutoSize = true;
                    groupII1.Name = "grpII1" + index;
                    this.pnl_Main.Controls.Add(groupII1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupII1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtII1" + index;
                    this.pnl_Main.Controls[groupII1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK1 II.2

                AddII_2(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddII_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbII2 = AddLabel(this.pnl_Main, "lbII2", "II/ Match", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupII2 = new Panel();
                    groupII2.Location = new Point(10, y + 20);
                    groupII2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupII2.AutoSize = true;
                    groupII2.Name = "grpII2" + index;
                    this.pnl_Main.Controls.Add(groupII2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupII2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtII2" + index;
                    this.pnl_Main.Controls[groupII2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK1 II.3

                AddII_3(1, 3, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddII_3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈ3 = AddLabel(this.pnl_Main, "lbII3", "III/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupII3 = new Panel();
                    groupII3.Location = new Point(10, y + 20);
                    groupII3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupII3.AutoSize = true;
                    groupII3.Name = "grpII3" + index;
                    this.pnl_Main.Controls.Add(groupII3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupII3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtII3" + index;
                    this.pnl_Main.Controls[groupII3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK1 II.4

                AddII_4(1, 2, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddII_4(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈ4 = AddLabel(this.pnl_Main, "lbII4", "IV/ Write t(true) or f(false)", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupII4 = new Panel();
                    groupII4.Location = new Point(10, y + 20);
                    groupII4.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupII4.AutoSize = true;
                    groupII4.Name = "grpII4" + index;
                    this.pnl_Main.Controls.Add(groupII4);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupII4.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtII4" + index;
                    this.pnl_Main.Controls[groupII4.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK2 III.1
                Label lbMK2 = AddLabel(this.pnl_Main, "lbMK2", "MK2", Color.Red, y + 50);

                AddIII_1(1, 4, lbMK2.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //III MK2
        private void AddIII_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈI1 = AddLabel(this.pnl_Main, "lbIII1", "I/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIII1 = new Panel();
                    groupIII1.Location = new Point(10, y + 20);
                    groupIII1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIII1.AutoSize = true;
                    groupIII1.Name = "grpIII1" + index;
                    this.pnl_Main.Controls.Add(groupIII1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIII1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtIII1" + index;
                    this.pnl_Main.Controls[groupIII1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK2 III.2

                AddIII_2(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddIII_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈI2 = AddLabel(this.pnl_Main, "lbIII2", "II/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIII2 = new Panel();
                    groupIII2.Location = new Point(10, y + 20);
                    groupIII2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIII2.AutoSize = true;
                    groupIII2.Name = "grpIII2" + index;
                    this.pnl_Main.Controls.Add(groupIII2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIII2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 200;
                    txt1.Name = "txtIII2" + index;
                    this.pnl_Main.Controls[groupIII2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK2 III.3

                AddIII_3(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddIII_3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈI3 = AddLabel(this.pnl_Main, "lbIII3", "III/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIII3 = new Panel();
                    groupIII3.Location = new Point(10, y + 20);
                    groupIII3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIII3.AutoSize = true;
                    groupIII3.Name = "grpIII3" + index;
                    this.pnl_Main.Controls.Add(groupIII3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIII3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtIII3" + index;
                    this.pnl_Main.Controls[groupIII3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK2 III.4

                AddIII_4(1, 2, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddIII_4(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIỈI4 = AddLabel(this.pnl_Main, "lbIII4", "IV/ Write Yes, it is. or No, it isn’t", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIII4 = new Panel();
                    groupIII4.Location = new Point(10, y + 20);
                    groupIII4.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIII4.AutoSize = true;
                    groupIII4.Name = "grpIII4" + index;
                    this.pnl_Main.Controls.Add(groupIII4);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIII4.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 200;
                    txt1.Name = "txtIII4" + index;
                    this.pnl_Main.Controls[groupIII4.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK3 IV.1
                Label lbMK3 = AddLabel(this.pnl_Main, "lbMK3", "MK3", Color.Red, y + 50);
                AddIV_1(1, 5, lbMK3.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //IV MK3
        private void AddIV_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIV1 = AddLabel(this.pnl_Main, "lbIV1", "I/ Read and write t(true) or f(false) ", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIV1 = new Panel();
                    groupIV1.Location = new Point(10, y + 20);
                    groupIV1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIV1.AutoSize = true;
                    groupIV1.Name = "grpIV1" + index;
                    this.pnl_Main.Controls.Add(groupIV1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIV1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtIV1" + index;
                    this.pnl_Main.Controls[groupIV1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK3 IV.2

                AddIV_2(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddIV_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIV2 = AddLabel(this.pnl_Main, "lbIV2", "II/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIV2 = new Panel();
                    groupIV2.Location = new Point(10, y + 20);
                    groupIV2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIV2.AutoSize = true;
                    groupIV2.Name = "grpIV2" + index;
                    this.pnl_Main.Controls.Add(groupIV2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIV2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtIV2" + index;
                    this.pnl_Main.Controls[groupIV2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK3 IV.3

                AddIV_3(1, 2, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddIV_3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbIV3 = AddLabel(this.pnl_Main, "lbIV3", "III/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupIV3 = new Panel();
                    groupIV3.Location = new Point(10, y + 20);
                    groupIV3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupIV3.AutoSize = true;
                    groupIV3.Name = "grpIV3" + index;
                    this.pnl_Main.Controls.Add(groupIV3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupIV3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 200;
                    txt1.Name = "txtIV3" + index;
                    this.pnl_Main.Controls[groupIV3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK4 V.1
                Label lbMK4 = AddLabel(this.pnl_Main, "lbMK4", "MK4", Color.Red, y + 50);
                AddV_1(1, 8, lbMK4.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //V MK4
        private void AddV_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbV1 = AddLabel(this.pnl_Main, "lbV1", "I/ Write ", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupV1 = new Panel();
                    groupV1.Location = new Point(10, y + 20);
                    groupV1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupV1.AutoSize = true;
                    groupV1.Name = "grpV1" + index;
                    this.pnl_Main.Controls.Add(groupV1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupV1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtV1" + index;
                    this.pnl_Main.Controls[groupV1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK4 V.2

                AddV_2(1, 2, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddV_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbV2 = AddLabel(this.pnl_Main, "lbV2", "II/ Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupV2 = new Panel();
                    groupV2.Location = new Point(10, y + 20);
                    groupV2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupV2.AutoSize = true;
                    groupV2.Name = "grpV2" + index;
                    this.pnl_Main.Controls.Add(groupV2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupV2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 200;
                    txt1.Name = "txtV2" + index;
                    this.pnl_Main.Controls[groupV2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK5 VI.1
                Label lbMK5 = AddLabel(this.pnl_Main, "lbMK5", "MK5", Color.Red, y + 50);
                AddVI_1(1, 3, lbMK5.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //VI MK5
        private void AddVI_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVI1 = AddLabel(this.pnl_Main, "lbVI1", "I/ Read and circle ", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVI1 = new Panel();
                    groupVI1.Location = new Point(10, y + 20);
                    groupVI1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVI1.AutoSize = true;
                    groupVI1.Name = "grpVI1" + index;
                    this.pnl_Main.Controls.Add(groupVI1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVI1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtVI1" + index;
                    this.pnl_Main.Controls[groupVI1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK5 VI.2

                AddVI_2(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddVI_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVI2 = AddLabel(this.pnl_Main, "lbVI2", "II/ Unscramble and Write", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVI2 = new Panel();
                    groupVI2.Location = new Point(10, y + 20);
                    groupVI2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVI2.AutoSize = true;
                    groupVI2.Name = "grpVI2" + index;
                    this.pnl_Main.Controls.Add(groupVI2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVI2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 300;
                    txt1.Name = "txtVI2" + index;
                    this.pnl_Main.Controls[groupVI2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK5 VI.3

                AddVI_3(1, 4, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddVI_3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVI3 = AddLabel(this.pnl_Main, "lbVI3", "III/ Write the correct sentences", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVI3 = new Panel();
                    groupVI3.Location = new Point(10, y + 20);
                    groupVI3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVI3.AutoSize = true;
                    groupVI3.Name = "grpVI3" + index;
                    this.pnl_Main.Controls.Add(groupVI3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVI3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 300;
                    txt1.Name = "txtVI3" + index;
                    this.pnl_Main.Controls[groupVI3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK6 VII.1
                Label lbMK6 = AddLabel(this.pnl_Main, "lbMK6", "MK6", Color.Red, y + 50);
                AddVII_1(1, 3, lbMK6.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //MK6
        private void AddVII_1(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVII1 = AddLabel(this.pnl_Main, "lbVII1", "I/ (v = Yes, X = No) ", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVII1 = new Panel();
                    groupVII1.Location = new Point(10, y + 20);
                    groupVII1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVII1.AutoSize = true;
                    groupVII1.Name = "grpVII1" + index;
                    this.pnl_Main.Controls.Add(groupVII1);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVII1.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 300;
                    txt1.Name = "txtVII1" + index;
                    this.pnl_Main.Controls[groupVII1.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK6 VII.2

                AddVII_2(1, 5, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddVII_2(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVII2 = AddLabel(this.pnl_Main, "lbVII2", "II/ Write and order", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVII2 = new Panel();
                    groupVII2.Location = new Point(10, y + 20);
                    groupVII2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVII2.AutoSize = true;
                    groupVII2.Name = "grpVII2" + index;
                    this.pnl_Main.Controls.Add(groupVII2);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVII2.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 300;
                    txt1.Name = "txtVII2" + index;
                    this.pnl_Main.Controls[groupVII2.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK6 VII.3

                AddVII_3(1, 6, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddVII_3(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVII3 = AddLabel(this.pnl_Main, "lbVII3", "III/ Read and choose the best answer", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVII3 = new Panel();
                    groupVII3.Location = new Point(10, y + 20);
                    groupVII3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVII3.AutoSize = true;
                    groupVII3.Name = "grpVII3" + index;
                    this.pnl_Main.Controls.Add(groupVII3);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVII3.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 20;
                    txt1.Name = "txtVII3" + index;
                    this.pnl_Main.Controls[groupVII3.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }

                //Add MK7-8 VIII.0
                Label lbMK7 = AddLabel(this.pnl_Main, "lbMK7", "MK7-8", Color.Red, y + 50);
                AddVIII(1, 10, lbMK7.Location.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //MK7-8
        private void AddVIII(int begin, int end, int y)
        {
            try
            {
                y += 50;
                Label lbVIII0 = AddLabel(this.pnl_Main, "lbVIII0", "Choose and write words from the box for a good review and a bad review. You will use one word twice", Color.Blue, y);

                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupVIII0 = new Panel();
                    groupVIII0.Location = new Point(10, y + 20);
                    groupVIII0.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupVIII0.AutoSize = true;
                    groupVIII0.Name = "grpVIII0" + index;
                    this.pnl_Main.Controls.Add(groupVIII0);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    this.pnl_Main.Controls[groupVIII0.Name].Controls.Add(lb);

                    TextBox txt1 = new TextBox();
                    txt1.Location = new Point(lb.Location.X + 20, lb.Location.Y);
                    txt1.Width = 100;
                    txt1.Name = "txtVIII0" + index;
                    this.pnl_Main.Controls[groupVIII0.Name].Controls.Add(txt1);
                    txt1.TextChanged += new EventHandler(TextBox_TextChanged);

                    y += 20;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region "Load Other"
        private void LoadEnquiry()
        {
            try
            {
                string sql = String.Format(@"select EnquiryNumber, (Holot + ' ' + Ten) as 'FullName'
                                            from Enquiry");
                SqlDataAdapter da = new SqlDataAdapter(sql, GlobalVariable.WSInfo.ConnectionString);
                da.Fill(ds, "TableEnquiry");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void LoadMusic(string filename)
        {
            try
            {
                axWindowsMediaPlayer1.URL = Environment.CurrentDirectory + "/" + filename;
                axWindowsMediaPlayer1.Ctlcontrols.play();
                axWindowsMediaPlayer1.Ctlenabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void LoadTime()
        {
            try
            {
                progressBarTime.Maximum = _thoigianlambai;
                progressBarTime.Value = progressBarTime.Maximum;

                lblTimeLeft.Text = "Time left (minutes): " + progressBarTime.Value.ToString();

                timerTest.Interval = 1000 * _thoigianlambai;
                timerTest.Start();

                btn_Start.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void InsertTestResult(string enqnum, DateTime testdate, int listening, int reading, string madethi)
        {
            try
            {
                //MessageBox.Show(testdate.ToString());
                SQLHelper.ExecuteNonQuery(GlobalVariable.WSInfo.ConnectionString,
                                        String.Format(@"usp_InsertTestResult @enquirynumber = '{0}', @testdate = '{1}', @scoredirection = {2}, @scorelistening = {3}, 
                                                        @scorereading = {4}, @scorewriting = {5}, @madethi = '{6}', @ketqua = '{7}', @recommendedclass = '{8}'",
                                                        enqnum, testdate, 0, listening, reading, 0, madethi, "", ""));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region "Common method"
        //Common method

        private int AddABCD(Panel panel, int begin, int end, int y, string chimuc)
        {
            try
            {
                for (int i = begin; i <= end; i++)
                {
                    string index = (i < 10) ? "0" + i : i.ToString();
                    Panel groupABCD = new Panel();
                    groupABCD.Location = new Point(10, y + 20);
                    groupABCD.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    groupABCD.AutoSize = true;
                    groupABCD.Name = "grp" + chimuc + index;
                    panel.Controls.Add(groupABCD);

                    Label lb = new Label();
                    lb.AutoSize = true;
                    lb.Location = new Point(10, 20);
                    lb.Text = i.ToString();
                    panel.Controls[groupABCD.Name].Controls.Add(lb);

                    RadioButton rda = new RadioButton();
                    rda.Location = new Point(lb.Location.X + 30, lb.Location.Y);
                    rda.Text = "a.";
                    rda.Name = "a" + chimuc + index;
                    rda.AutoSize = true;
                    panel.Controls[groupABCD.Name].Controls.Add(rda);
                    rda.CheckedChanged += new System.EventHandler(RadioButtonABCD_CheckedChanged);

                    RadioButton rdb = new RadioButton();
                    rdb.Location = new Point(rda.Location.X + 100, rda.Location.Y);
                    rdb.Text = "b.";
                    rdb.Name = "b" + chimuc + index;
                    rdb.AutoSize = true;
                    panel.Controls[groupABCD.Name].Controls.Add(rdb);
                    rdb.CheckedChanged += new System.EventHandler(RadioButtonABCD_CheckedChanged);

                    RadioButton rdc = new RadioButton();
                    rdc.Location = new Point(rdb.Location.X + 100, rda.Location.Y - 1);
                    rdc.Text = "c.";
                    rdc.Name = "c" + chimuc + index;
                    rdc.AutoSize = true;
                    panel.Controls[groupABCD.Name].Controls.Add(rdc);
                    rdc.CheckedChanged += new System.EventHandler(RadioButtonABCD_CheckedChanged);

                    RadioButton rdd = new RadioButton();
                    rdd.Location = new Point(rdc.Location.X + 100, rda.Location.Y - 2);
                    rdd.Text = "d.";
                    rdd.Name = "d" + chimuc + index;
                    rda.AutoSize = true;
                    panel.Controls[groupABCD.Name].Controls.Add(rdd);
                    rdd.CheckedChanged += new System.EventHandler(RadioButtonABCD_CheckedChanged);

                    y += 20;
                }
                return y;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return 0;
            }
        }

        private Label AddLabel(Panel panel, string name, string text, Color color, int y)
        {
            try
            {
                Label lb = new Label();
                lb.Location = new Point(10, y);
                lb.AutoSize = true;
                lb.Name = name;
                lb.ForeColor = color;
                lb.Text = text;
                panel.Controls.Add(lb);
                return lb;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
        #endregion

        #region "Get Value"
        private void RadioButtonABCD_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                RadioButton r = ((RadioButton)sender);
                string indexandstt = r.Name.ToString().Substring(1);
                string ndung = (r.Name.ToString().Substring(0, 1) == null) ? "" : r.Name.ToString().Substring(0, 1);
                this.pnl_Main.Controls["grp" + indexandstt].Tag = ndung;
                //MessageBox.Show(indexandstt + "/" + this.pnl_Main.Controls["grp" + indexandstt].Tag.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                TextBox t = (TextBox)sender;
                string indexandstt = t.Name.Substring(3);
                string ndung = (t.Text == null) ? "" : t.Text;
                this.pnl_Main.Controls["grp" + indexandstt].Tag = ndung;
                //MessageBox.Show(indexandstt + "/" + this.pnl_Main.Controls["grp" + indexandstt].Tag.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region "Get Result"
        private SqlDataReader GetResult(string chimuc)
        {
            try
            {
                SqlDataReader rd = SQLHelper.ExecuteReader(GlobalVariable.WSInfo.ConnectionString,
                                    String.Format(@"declare @chimuc varchar(10)
                                    set @chimuc = '{0}'
                                    select Substring(MaCauHoi, 4, LEN(MaCauHoi) - 3) as 'MaCauHoi', lower(DapAn) as 'DapAn'
                                    from TEST_Question 
                                    where MaDeThi = '{1}' 
                                    and SUBSTRING(MaCauHoi, 4, LEN(@chimuc)) = @chimuc", chimuc, _madethi));
                return rd;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
        #endregion

        #region "Mathing"
        private void Mathing()
        {
            try
            {
                SqlDataReader rd;
                int correctI1, correctI2, correctII1, correctII2, correctII3, correctII4, correctIII1, correctIII2, correctIII3, correctIII4, 
                    correctIV1, correctIV2, correctIV3, correctV1, correctV2, correctVI1, correctVI2, correctVI3,
                    correctVII1, correctVII2, correctVII3, correctVIII;
                correctI1 = correctI2 = 
                    correctII1 = correctII2 = correctII3 = correctII4 = 
                    correctIII1 = correctIII2 = correctIII3 = correctIII4 
                    = correctIV1 = correctIV2 = correctIV3 = 
                correctV1 = correctV2 = 
                correctVI1 = correctVI2 = correctVI3 = 
                correctVII1 = correctVII2 = correctVII3 = 
                correctVIII = 0;

                //I.1
                rd = GetResult("I1");
                correctI1 = CountCorrect(rd);

                //I.2
                rd = GetResult("I2");
                correctI2 = CountCorrect(rd);

                //II.1
                rd = GetResult("II1");
                correctII1 = CountCorrect(rd);

                //II.2
                rd = GetResult("II2");
                correctII2 = CountCorrect(rd);

                //II.3
                rd = GetResult("II3");
                correctII3 = CountCorrect(rd);

                //II.4
                rd = GetResult("II4");
                correctII4 = CountCorrect(rd);

                //III.1
                rd = GetResult("III1");
                correctIII1 = CountCorrect(rd);

                //III.2
                rd = GetResult("III2");
                correctIII2 = CountCorrect(rd);

                //III.3
                rd = GetResult("III3");
                correctIII3 = CountCorrect(rd);

                //III.4
                rd = GetResult("III4");
                correctIII4 = CountCorrect(rd);

                //IV.1
                rd = GetResult("IV1");
                correctIV1 = CountCorrect(rd);

                //IV.2
                rd = GetResult("IV2");
                correctIV2 = CountCorrect(rd);

                //IV.3
                rd = GetResult("IV3");
                correctIV3 = CountCorrect(rd);

                //V.1
                rd = GetResult("V1");
                correctV1 = CountCorrect(rd);

                //V.2
                rd = GetResult("V2");
                correctV2 = CountCorrect(rd);

                //VI.1
                rd = GetResult("VI1");
                correctVI1 = CountCorrect(rd);

                //VI.2
                rd = GetResult("VI2");
                correctVI2 = CountCorrect(rd);

                //VI.3
                rd = GetResult("VI3");
                correctVI3 = CountCorrect(rd);

                //VII.1
                rd = GetResult("VII1");
                correctVII1 = CountCorrect(rd);

                //VII.2
                rd = GetResult("VII2");
                correctVII2 = CountCorrect(rd);

                //VII.3
                rd = GetResult("VII3");
                correctVII3 = CountCorrect(rd);

                //VIII
                rd = GetResult("VIII0");
                correctVIII = CountCorrect(rd);

                _listen = correctI1 + correctI2;
                _read = correctII1 + correctII2 + correctII3 + correctII4 + 
                        correctIII1 + correctIII2 + correctIII3 + correctIII4 + 
                        correctIV1 + correctIV2 + correctIV3 +
                        correctV1 + correctV2 +
                        correctVI1 + correctVI2 + correctVI3 +
                        correctVII1 + correctVII2 + correctVII3 +
                        correctVIII;

                lblResultListening.Text = "Listening: " + _listen;
                lblResultReading.Text = "Reading: " + _read;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private int CountCorrect(SqlDataReader rd)
        {
            try
            {
                int i = 0;
                while (rd.Read())
                {
                    if (this.pnl_Main.Controls["grp" + rd["MaCauHoi"].ToString()].Tag != null)
                    {
                        if (this.pnl_Main.Controls["grp" + rd["MaCauHoi"].ToString()].Tag.ToString() == rd["DapAn"].ToString().Trim())
                            i++;
                    }
                }
                return i;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return 0;
            }
        }
        #endregion

        private void btn_Start_Click(object sender, EventArgs e)
        {
            if (slook_Enquiry.EditValue.ToString() != "" && slook_Enquiry.EditValue != null)
            {
                this.btn_Start.Enabled = false;
                slook_Enquiry.Enabled = false;
                this.pnl_Main.Enabled = true;
                this.btn_Finish.Enabled = true;
                LoadTime();
                LoadMusic(String.Format("{0}.mp3", _madethi));
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn tên.");
            }
        }

        private void btn_Finish_Click(object sender, EventArgs e)
        {
            btn_Finish.Enabled = false;
            slook_Enquiry.Enabled = false;
            axWindowsMediaPlayer1.Ctlcontrols.stop();
            timerTest.Stop();
            MessageBox.Show("Finish");
            Mathing();

            InsertTestResult(slook_Enquiry.EditValue.ToString(), Convert.ToDateTime(txtTestDate.EditValue.ToString()), _listen,
                            _read, _madethi);
        }

        private void timerTest_Tick(object sender, EventArgs e)
        {
            if (progressBarTime.Value == 0)
            {
                timerTest.Stop();
                btn_Finish_Click(sender, e);
                MessageBox.Show("Test time has expired !", "Sorry");
                return;
            }
            progressBarTime.Value--;
            lblTimeLeft.Text = "Time left (minutes): " + progressBarTime.Value.ToString();
        }

        private void frmMK_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (btn_Finish.Enabled)
            {
                MessageBox.Show("Click <Finish button> to finish the test before closing form", "Placement Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
            }
        }
    }
}
